/**
 * 我的书架
 * @param {uid} uid [用户id]
 * @param {Int} type [类型]
 */
function myBookself(uid , type , page , isEnable){
	if(!page) page = 1;
	$.ajax({
		type:"post", 
		url:apiRoot + "/Home/Article/collectionAndBookSelf/",
		data:{
			uid : uid, 
			type : type ,
			page : page
		},
		async:false,
		dataType:'json', 
		beforeSend:function(){
			plus.nativeUI.showWaiting('加载中...');
		},
		complete:function(){    
			plus.nativeUI.closeWaiting(); 
		},
		success : function(data){
			if(data){
				var html = '';
				$.each(data, function(k ,v) {
					if(type == 1){
						html += '<li class="mui-table-view-cell mui-media mui-col-xs-4 mui-col-sm-4 list'+v.id+'">';
					    html += '<div data-id="'+v.id+'" data-price="'+v.price+'" class="list list2"><div class="img">';
					    html += '<img class="mui-media-object" src="'+getImgUrl(v.litpic , '../public/img/book.png')+'" /></div>';
						html += '<div class="mui-media-body"><div class="title">'+v.book_name+'</div></div></div> </li>';
					}else{  
						html += '<div data-id="'+v.id+'" data-price="'+v.price+'" class="list-p list booklists list'+v.id+'"><ul class="mui-table-view">';
						html += '<li class="mui-table-view-cell mui-media"><a>';
						html += '<img class="mui-media-object mui-pull-left" src="'+getImgUrl(v.litpic , '../public/img/book.png')+'">';
						html += '<div class="mui-media-body"><div><span class="mui-h5 back">'+v.book_name+'</span><p class="mui-pull-right">';
						if(parseInt(v.price) == 0){
							html += '<span class="mui-red">免费</span>';
						}else{
							html += parseInt(v.discount_price) == 0 ? '<span class="mui-red">'+v.price+'</span>元' : '<span class="mui-red">'+v.discount_price+'</span><span style="text-decoration:line-through;margin: 0 5px;">'+v.price+'</span>元';
						}
						html += '</p></div><p class="autor mui-h6" style="margin-top: 5px;">'+v.author+'</p>';
						html += '<p class="read mui-h6" style="margin: 3px 0;"><span class="num">'+v.num+'</span>人读过</p>';
						html += '<p class="time mui-h6">'+v.addtime+'</p></div></a></li></ul></div>';
					}
				});   
				$('.book_lists').append(html);
				toUrl()
				if(isEnable)isEnable.endPullUpToRefresh(false);
			}else{
				toast('没有更多的数据了'); 
				if(isEnable)isEnable.endPullUpToRefresh(true); 
			}
		},
		error : function(e){
			errorPrompt(e);
		}
	});
}

 
window.addEventListener('cancel' , function(result){ 
	if(result.detail.id != 0){ 
		if(result.detail.type == 0){
			$('.list'+result.detail.aid).show();
		}else{
			var page = plus.webview.currentWebview().id;
			if(page === 'book.html'){
				var html  = '<li class="mui-table-view-cell mui-media mui-col-xs-4 mui-col-sm-4 list'+result.detail.aid+'"">';
			    html += '<div data-id="'+result.detail.aid+'" data-price="'+result.detail.price+'" class="list list2" ><div class="img">';
			    html += '<img class="mui-media-object" src="'+getImgUrl(result.detail.litpic , '../public/img/book.png')+'" /></div>';
				html += '<div class="mui-media-body"><div class="title">'+result.detail.book_name+'</div></div></div> </li>';
				$('.book_lists').prepend(html);
				toUrl();
			}
		}
	}else{
		if(result.detail.type == 0){
			$('.list'+result.detail.aid).hide();	
		}else{
			$('.list'+result.detail.aid).remove();
		}
	}
})
 

/**
 * 跳转页面
 */
function toUrl(){
	$('.list').unbind(); 
	$('.list').on('tap' , function(){ 
		bookDetails($(this).attr('data-id') ,$(this).attr('data-price') , self.id );
	})
}
